<template>
	<view class="work-container">
		<view v-for="(mod,i) in modules" :key="i">
			<uni-section :title="mod.name" type="line"></uni-section>
			<view class="menu-content">
				<view class="menu-cell" v-for="(item,index) in mod.menus" :key="index"
					@click="handleNav(item.navigateTo,item.query,item)">
					<image :src="item.iconUrl || './static/icons/app-wtsb.svg'"></image>
					<view><text class="text">{{item.name}}</text></view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/auth'
	export default {
		data() {
			return {
				modules: []
			}
		},
		onLoad() {
			this.initMenu();
		},
		methods: {
			initMenu() {
				let menuList = this.$store.state.user.routers.slice(1);
				console.log(JSON.stringify(menuList));
				if (menuList && menuList.length > 0) {
					this.modules = menuList.map(item => {
						let temp = {
							name: item.meta.title,
							menus: []
						}
						temp.menus = item.children.map(menu => {
							console.log(JSON.stringify(menu));
							return {
								"name": menu.meta.title,
								"iconUrl": "../../static/icons/" + menu.meta.icon + ".svg",
								"navigateTo": "/" + menu.path,
								"query": menu.query
							}
						});
						return temp;
					})
				}
			},
			handleNav(url, query, item) {
				if (query) {
					let params = JSON.parse(query);
					url += "?1=1";
					for (let key in params) {
						url = url + "&" + key + "=" + params[key];
					}
				}
				this.$tab.navigateTo(url);
			}
		}
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.menu-content {
		width: 100%;
		padding: 11px 15px;
		background-color: #ffffff;
		border-radius: 10px;
		text-align: center;
		display: flex;
		align-items: center;
		flex-wrap: wrap;

	}

	.menu-cell {
		width: 24%;
		margin-bottom: 15px;
	}

	.menu-cell image {
		width: 24px;
		height: 24px;
		margin-top: 5px;
		margin-bottom: 10px;
	}

	.menu-cell text {
		font-family: 思源黑体;
		font-size: 13px;
		font-weight: normal;
		line-height: 16px;
		letter-spacing: 0px;

		color: #353B50;
	}
</style>